import os

from openai import OpenAI
from app.core.config import DASHSCOPE_API_KEY, DASHSCOPE_BASE_URL

# 封装一个通义大模型客户端
client = OpenAI(
    api_key=DASHSCOPE_API_KEY,
    base_url=DASHSCOPE_BASE_URL,
)

def chat_with_qwen(messages: list, model: str = "qwen-plus"):
    """
    调用通义千问（兼容 OpenAI 协议）进行聊天。
    """
    response = client.chat.completions.create(
        model=model,
        messages=messages,
    )
    return response.choices[0].message.content
